package com.system.provider;

import com.am.grid.export.RowCallback;
import com.am.ui.grid.AbstractBaseGridProvider;
import com.system.uitls.ChartUtils;
import com.system.uitls.CommonUtil;
import java.sql.SQLException;
import java.util.Map;

public class PatientRecordProvider extends AbstractBaseGridProvider
  implements RowCallback
{
  public String generateSql(Map<String, Object> map)
  {
    String startDate = CommonUtil.nullToEmptyString(map.get("startDate"));
    String endDate = CommonUtil.nullToEmptyString(map.get("endDate"));
    String dateType = CommonUtil.nullToEmptyString(map.get("dateType"));

    startDate = ChartUtils.parseToComplete(startDate, dateType);
    endDate = ChartUtils.parseToComplete(endDate, dateType);

    ChartUtils chart = new ChartUtils();
    chart.setSql("SELECT person_campus FROM sys_patient_record where create_time>=? and create_time<=? AND status='7' group by person_campus");
    chart.setName("person_campus");
    chart.setSum("sum(1)");

    setParamArray(new Object[] { startDate, endDate });
    return chart.generateSql("create_time", startDate, endDate, dateType);
  }

  public void extraProcess(Map<String, Object> map) throws SQLException
  {
    String value = CommonUtil.nullToEmptyString(map.get("person_campus"));
    if ("0".equals(value))
    {
      map.put("person_campus", "校本部");
    } else if ("1".equals(value))
      map.put("person_campus", "白云校区");
    else if ("2".equals(value))
      map.put("person_campus", "北校区");
    else if ("3".equals(value))
      map.put("person_campus", "西校区");
    else
      map.put("person_campus", "合计");
  }
}